package com.tmt.oss;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Autowired;

import com.swak.annotation.Context;
import com.swak.annotation.FluxService;
import com.swak.http.HttpService;
import com.swak.oss.OssResponse;
import com.swak.oss.aliyun.AbstractOssService;

/**
 * Oss 存储服务 -- 可以直接在IO线程中执行
 * 
 * @author lifeng
 */
@FluxService(context = Context.IO)
public class OssService extends AbstractOssService {

	/**
	 * http 服务
	 */
	@Autowired
	private HttpService httpService;

	/**
	 * Oss 配置
	 */
	@Autowired
	private OssConfigImpl config;

	/**
	 * 返回内部使用的 http 客户端
	 */
	@Override
	public HttpService getHttpService() {
		return httpService;
	}

	/**
	 * 生成上传的签名
	 */
	public Map<String, Object> generatePolicy(String key, Integer fileSize, long expire) {
		return this.generatePolicy(config, key, fileSize, expire);
	}

	/**
	 * 上传数据
	 *
	 * @param key
	 * @param data
	 * @return
	 */
	public CompletableFuture<OssResponse> putObject(String key, byte[] data) {
		return this.putObject(config, key, data);
	}

	/**
	 * 删除数据
	 * 
	 * @param key
	 * @return
	 */
	public CompletableFuture<OssResponse> delObject(String key) {
		return this.delObject(config, key);
	}
}
